home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoInsertLargeData.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.9 KB  |  204 lines

  1. /*
  2.  *   $RCSfile: undoInsertLargeData.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:04 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "pool.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "logaction.h"
  62. #include "openlog.h"
  63. #include "undo.h"
  64. #include "undo_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "log_extfuncs.h"
  67. #include "log_intfuncs.h"
  68. #include "util_funcs.h"
  69. #include "thread_globals.h"
  70. #include "bf_globals.h"
  71. #include "trans_globals.h"
  72. #include "sm_macro.h"
  73. #ifdef INIT_LRC_IS_LSN
  74. #    include "log_globals.h"
  75. #endif
  76.  
  77.  void
  78. undoInsertLargeData (
  79.  
  80.     LOGRECORDHDR        *recordHeader 
  81. )
  82. {
  83.  
  84.     GROUPLINK            *groupLink;
  85.     LGDATAPAGE            *lgDataPage;
  86.     char                *oldData;
  87.     int                    oldDataSize;
  88.     PID                    *pid;
  89.     LGWRITEINFO         *lgWriteInfo;
  90.     LGWRITEINFO         newLgWriteInfo;
  91.     LOGRECORDINFO       recordInfo;
  92. #ifdef INIT_LRC_IS_LSN
  93.     LRC                 tempLRC;
  94.     LRC                 *lrc = &tempLRC;
  95. #else
  96.     LRC                 *lrc;
  97. #endif /* INIT_LRC_IS_LSN; */
  98.     LSN                    lsn;
  99.     FORCEMARK            forceMark;
  100.     BOOL                actionDone;    /* Indicates whether the action
  101.                                        was ever performed on the page */
  102.     int                    i;
  103.     INIT_MISSING_UPDATE_INFO( Active->transRec );
  104.  
  105.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  106.  
  107.     /* get a pointer to the page for the record */
  108.     pid = &(recordHeader->actionPid);
  109.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  110.  
  111.     /* get pointer to oid, header info */
  112.     lgWriteInfo = (LGWRITEINFO*) GET_LOG_IMAGE(recordHeader, 0);
  113.  
  114.     if (recordHeader->action == LOG_ACTION_INSERT_LARGE_DATA) {
  115.         /* get a pointer to the old data and its size in the record */
  116.         oldData = GET_LOG_IMAGE(recordHeader, 1);
  117.         oldDataSize = GET_LOG_IMAGE_SIZE(recordHeader, 1);
  118.         SM_ASSERT(LEVEL_3, oldDataSize == lgWriteInfo->size);
  119.     } else {
  120.         SM_ASSERT(LEVEL_3, recordHeader->action == LOG_ACTION_INSERT_LARGE_DATA_ND);
  121.     }
  122.  
  123.     /*
  124.      *    read in the page
  125.      */
  126.     if ((groupLink = bf_ReadPage(UserBufGroup, pid, LGDATA_PAGE2SIZE, BF_SEM)) == NULL) {
  127.  
  128.         SM_ERROR(TYPE_FATAL, Active->errno);
  129.     }
  130.  
  131.     /* get a pointer to the large data page */
  132.     lgDataPage = (LGDATAPAGE *) groupLink->bufFrame;
  133.     CHECK_LGDATAHDR_MAGIC(lgDataPage);
  134.  
  135.     /* See if the action was actually done */ 
  136.      actionDone = compareLRC(&(recordHeader->actionLRC), &(lgDataPage->header.lrc) ) <= 0;
  137.     
  138.     /*
  139.      *    it is possible that the action 
  140.      *    never made it to the page on the server, so missing update
  141.      *    information may need to be recorded
  142.      *
  143.      *    Process any missing updates, and return a pointer to
  144.      *    the lrc to increment.  This will either be the lrc on the
  145.      *    slotted page, or the lrc in the missingUpdatePageTable
  146.      */
  147.     RECORD_MISSING_UPDATE( actionDone, &lrc, missingUpdateInfo, pid,
  148.                          &(lgDataPage->header.lrc),
  149.                          groupLink->pageHash, recordHeader, PAGE_LARGEDATA);
  150.  
  151.     /* increment the lrc on the page */
  152.     GENERATE_LRC(lrc);
  153.  
  154.     newLgWriteInfo = *lgWriteInfo;
  155.     newLgWriteInfo.prevSize = lgWriteInfo->prevSize + lgWriteInfo->size;
  156.     
  157.     /*
  158.      *    Log the undo write
  159.      */
  160.     recordInfo.action       = LOG_ACTION_DELETE_LARGE_DATA;
  161.     recordInfo.type         = LOG_REC_TYPE_COMPENSATION;
  162.     recordInfo.imageCount   = 1;
  163.     recordInfo.actionPid    = pid;
  164.     recordInfo.actionLRC    = lrc;
  165.     recordInfo.imageSize[0] = sizeof(LGWRITEINFO);
  166.     recordInfo.imageData[0] = (VOID *) &newLgWriteInfo;
  167.     recordInfo.nextUndoLSN  = recordHeader->previousLSN;
  168.     recordInfo.flags        = NOFLAGS;
  169.  
  170.     /* write the record to the log */
  171.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
  172.                               &lsn, NOFLAGS)) < 0)  {
  173.         SM_ERROR(TYPE_FATAL, Active->errno);
  174.     }
  175.  
  176.     /* mark the page dependency */
  177. #ifndef INIT_LRC_IS_LSN
  178.     DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  179. #endif
  180.  
  181.     /* perform the undo, if the action was performed */
  182.     if (actionDone) {
  183.  
  184. #ifdef INIT_LRC_IS_LSN
  185.         DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  186. #endif
  187.  
  188.         /* Delete the inserted data */
  189.         for (i = lgWriteInfo->start+oldDataSize; i < lgWriteInfo->prevSize+oldDataSize; i++) {
  190.             lgDataPage->data[i-oldDataSize] = lgDataPage->data[i];
  191.         }
  192.         CHECK_LGDATAHDR_MAGIC(lgDataPage);
  193.     }
  194.  
  195.     /*
  196.      *    release the semaphore and unfix the page, dirty the page if
  197.      *    the action was done
  198.      */
  199.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  200.     bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
  201.  
  202.     return;
  203. }
  204.